#include "simple_graph_parsing.h"
#include "protein_graph_parsing.h"
#include "processing.h"

void print_help()
{
	std::clog << "Masugo usage:\n"
	             "  masugo --file FILENAME --support SUPPORT [--only-subtrees] [--steps STEPS --step-size STEP_SIZE]\n"
	             "Where:\n"
	             "  FILENAME - graph database file path\n"
	             "  SUPPORT - support threshold, 0.0<SUPPORT<=1.0\n"
	             "  STEPS - support threshold decrement times, STEPS>0\n"
	             "  STEP_SIZE - support threshold decrement per step, STEP_SIZE>0.0\n";
}

int main(const int argc, const char** argv)
{
	if(argc<2)
	{
		print_help();
		return 0;
	}

	try
	{
		utilities::CommandLineOptions clo(argc, argv);
		const std::string file=clo.arg<std::string>("--file");
		const double support=clo.arg<double>("--support");
		if(support<=0.0) { throw std::invalid_argument("Support value is not positive."); }
		const bool only_subtrees=clo.isopt("--only-subtrees");
		const int support_steps=clo.isopt("--steps") ? std::max(0, clo.arg<int>("--steps")) : 0;
		const double support_step_size=support_steps>0 ? clo.arg<double>("--step-size") : 1.0;
		if(support_step_size<=0.0) { throw std::invalid_argument("Support value step size is not positive."); }

		typedef masugo::simple_graph_parsing< masugo::Graph<int, int, int> > simple_gp;
		typedef masugo::protein_graph_parsing protein_gp;

		if(simple_gp::check_file_start(file.c_str())) { masugo::processing<simple_gp>::process(file, support, only_subtrees, support_steps, support_step_size); }
		else { masugo::processing<protein_gp>::process(file, support, only_subtrees, support_steps, support_step_size); }
	}
	catch(const std::exception& e)
	{
		std::cerr << "Exception caught: (" << e.what() << ")\n";
	}

	return 0;
}
